package com.chen.controller;


import com.chen.base.PageResponse;
import com.chen.base.ResponseResult;
import com.chen.dto.NursingProjectDto;
import com.chen.service.NursingProjectService;
import com.chen.vo.NursingProjectVo;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * 狐狸
 */
@RestController
@RequestMapping("nursing_project")
public class NursingProjectController extends BaseController {

    @Resource
    private NursingProjectService nursingProjectService;

    /**
     * 分页查询护理项目列表
     */
    @GetMapping
    public ResponseResult<PageResponse<NursingProjectVo>> getByPage(
            @RequestParam(value = "name", required = false) String name,
            @RequestParam(value = "status", required = false) Integer status,
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        PageResponse<NursingProjectVo> nursingProjectPageInfo = nursingProjectService.getByPage(name, status, pageNum, pageSize);
        return success(nursingProjectPageInfo);
    }

    /**
     * 新增护理项目
     */
    @PostMapping
    public ResponseResult add(@RequestBody NursingProjectDto nursingProjectDTO) {
        nursingProjectService.add(nursingProjectDTO);
        return ResponseResult.success();
    }

    /**
     * 根据编号查询护理项目信息
     *
     * @param id 护理项目编号
     * @return 护理项目信息
     */
    @GetMapping("/{id}")
    public ResponseResult<NursingProjectVo> getById(@PathVariable("id") Long id) {
        NursingProjectVo nursingProjectVO = nursingProjectService.getById(id);
        return ResponseResult.success(nursingProjectVO);
    }

    /**
     * 更新护理项目信息
     *
     * @param nursingProjectDTO 护理项目数据传输对象
     * @return 操作结果
     */
    @PutMapping
    public ResponseResult update(@RequestBody NursingProjectDto nursingProjectDTO) {
        nursingProjectService.update(nursingProjectDTO);
        return ResponseResult.success();
    }

    /**
     * 删除护理项目信息
     *
     * @param id 护理项目编号
     * @return 操作结果
     */
    @DeleteMapping("/{id}")
    public ResponseResult deleteById(@PathVariable("id") Long id) {
        NursingProjectVo nursingProjectVO = nursingProjectService.getById(id);
        if (nursingProjectVO == null) {
            return ResponseResult.error();
        }
        nursingProjectService.deleteById(id);
        return ResponseResult.success();
    }

    /**
     * 启用/禁用护理项目
     * @param id id
     * @param status 状态
     * @return 操作结果
     */
    @PutMapping("/{id}/status/{status}")
    public ResponseResult enableOrDisable(@PathVariable Long id, @PathVariable Integer status) {
        nursingProjectService.enableOrDisable(id, status);
        return ResponseResult.success();
    }

    /**
     *查询所有护理项目
     * @return  操作结果
     */
    @GetMapping("/all")
    public ResponseResult<List<NursingProjectVo>> getAllNursingProject() {
        List<NursingProjectVo> nursingProjectVos = nursingProjectService.listAll();
        return ResponseResult.success(nursingProjectVos);
    }
}
